<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <button id="btn">存</button>
  <button id="btn2">取</button>
  <button id="btn3">删</button>
  <body>
    <script>
      // 存---只能存字符串
      btn.onclick = function () {
        console.log(localStorage.setItem('name', 'cxm')) //存
      }
      btn2.onclick = function () {
        console.log(localStorage.getItem('name')) //取
      }
      btn3.onclick = function () {
        console.log(localStorage.removeItem('name')) //删
      }

      // 永久存储：localStorage
      // 临时存储：sessionStorage 关闭页面丢失
    </script>
  </body>
</html>
